//
//  LKFeedBackViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/28.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKFeedBackViewController.h"

@interface LKFeedBackViewController ()<UITextViewDelegate>

@property(nonatomic,strong)UITextView *textView;
@property(nonatomic,strong)LKBaseLabel *placeLabel;
@end

@implementation LKFeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"意见反馈";
    [self crateHeaderImageView];
    // Do any additional setup after loading the view.
}


-(void)crateHeaderImageView{
    WS(weakSelf)
    UIImageView *imageV = [[UIImageView alloc] init];
    imageV.image = [UIImage imageNamed:@"AppIcon60x60"];
    [self.view addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(NAVIGATION_BAR_HEIGHT + 50);
        make.centerX.equalTo(self.view);
    }];
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(20);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.top.equalTo(imageV.mas_bottom).offset(30);
        make.height.mas_equalTo(200);
    }];
    self.textView = [[UITextView alloc] init];
    self.textView.backgroundColor = [UIColor whiteColor];
    self.textView.delegate = self;
    self.textView.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    [bgView addSubview:_textView];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset(0);
        make.right.equalTo(bgView.mas_right).offset(0);
        make.top.equalTo(bgView.mas_top).offset(0);
        make.bottom.equalTo(bgView.mas_bottom);
    }];
    self.placeLabel = [LKBaseLabel labelWithFrame:CGRectZero text:@"请输入意见" textColor:[UIColor lightGrayColor] font:[UIFont fontWithName:@"PingFangSC-Regular" size:16] textAlignment:NSTextAlignmentLeft];
    [self.textView addSubview:_placeLabel];
    [_placeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.textView.mas_right).offset(0);
        make.top.equalTo(self.textView.mas_top).offset(5);
    }];
//    [bgView bringSubviewToFront:placeLabel];
    LKBaseButton *submmitBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@"提交" titleColor:[UIColor whiteColor] layercorne:25 font:[UIFont fontWithName:@"PingFangSC-Medium" size:18] backgroudColor:yellowDefaultColor AndActionBlock:^(UIButton * _Nonnull btn) {
        if (weakSelf.textView.text.length == 0) {
            [SVProgressHUD showInfoWithStatus:@"请输入您的意见"];
            return ;
        }
        NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithDictionary:@{@"content":weakSelf.textView.text}];
        NSString *sign = [NSString encoingWithDic:param];
        [param setObject:sign forKey:@"sign"];
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyFeedbackUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            if ([responseObject[@"code"] isEqualToString:@"success"]) {
                [SVProgressHUD showInfoWithStatus:@"提交成功，我们会尽快回复你"];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadFeedBackNotice" object:nil];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }else{
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            }

        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }];
    [self.view addSubview:submmitBtn];
    [submmitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(30);
        make.left.equalTo(self.view).offset(10);
        make.height.mas_equalTo(50);
        make.centerX.equalTo(self.view);
    }];
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if (textView.text.length == 0) {
        self.placeLabel.hidden = NO;
    }else{
        self.placeLabel.hidden = YES;
    }
    return YES;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
